/*
** Copyright (C) 2010 Calin Radoni
**
** This file is part of CHScanner.
**
** CHScanner is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** CHScanner is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with CHScanner. If not, see <http://www.gnu.org/licenses/>.
*/

#include "StdAfx.h"
#include ".\mcclabel.h"

//---------------------------------------------------------------------------

IMPLEMENT_DYNAMIC(MCCLabel, CStatic)
MCCLabel::MCCLabel(void) : CStatic()
{
	changeTextColor = true;
	textColor = RGB(0xFF, 0, 0xFF);
}

MCCLabel::~MCCLabel(void)
{
}

//---------------------------------------------------------------------------

BEGIN_MESSAGE_MAP(MCCLabel, CStatic)
	ON_WM_PAINT()
END_MESSAGE_MAP()

//---------------------------------------------------------------------------

void MCCLabel::OnPaint()
{
	CPaintDC dc(this); // device context for painting

	CRect rect;
	CString title;
	CFont *theFont;
	CFont *oldFont;
	DWORD style;
	DWORD format;
	COLORREF oldColor;

	GetClientRect(rect);
	GetWindowText(title);

	// Get the font
	theFont = GetFont();
	oldFont = dc.SelectObject(theFont);

	style = GetStyle();
	format = 0;

	if(style & SS_RIGHT)        format |= DT_RIGHT;
	if(style & SS_CENTER)       format |= DT_CENTER;
	if(style & SS_CENTERIMAGE)  format |= DT_VCENTER | DT_SINGLELINE;
	if(style & SS_NOPREFIX)     format |= DT_NOPREFIX;
	if(style & SS_WORDELLIPSIS) format |= DT_WORD_ELLIPSIS;
	if(style & SS_ENDELLIPSIS)  format |= DT_END_ELLIPSIS;
	if(style & SS_PATHELLIPSIS) format |= DT_PATH_ELLIPSIS;

	if(!(style & (SS_LEFTNOWORDWRAP | SS_CENTERIMAGE | SS_WORDELLIPSIS | SS_ENDELLIPSIS | SS_PATHELLIPSIS))) format |= DT_WORDBREAK;

	// Set transparent background
	dc.SetBkMode(TRANSPARENT);

	// Save old text color ...
	oldColor = dc.GetTextColor();
	// and change it
	if(changeTextColor)
		dc.SetTextColor(textColor);

	// Draw the text
	dc.DrawText(title, rect, format);

	// Restore original text color
	dc.SetTextColor(oldColor);

	// Select old font
	dc.SelectObject(oldFont);
}

//---------------------------------------------------------------------------
